/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sysdance.aplicativo.util.visao;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

/**
 *
 * @author gocard
 */
public class JanelaDialogo extends javax.swing.JDialog {

    private static final KeyStroke KEY_STROKE_ESC = KeyStroke.getKeyStroke(
            KeyEvent.VK_ESCAPE, 0);

    protected void fecharJanela() {
        dispose();
    }

    private void initEscListener() {
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
                KEY_STROKE_ESC, "close");
        getRootPane().getActionMap().put("close", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                fecharJanela();
            }
        });
    }
    public JanelaDialogo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initEscListener();
    }
}
